package com.foo.designpattern.interpreter;

/**
 * com.foo.designpattern.interpreter
 * Created with IntelliJ IDEA.
 * Created by jiang on 2016-06-12 15:03.
 *
 * @Description 非终结符表达式(Non Terminal Expression)角色--Not
 * 代表逻辑"非"操作的Not类，代表由一个布尔表达式通过逻辑"非"操作给出一个新的布尔表达式的操作。
 */

public class Not implements Expression {
    private Expression exp;

    public Not(Expression exp) {
        this.exp = exp;
    }

    @Override
    public boolean interpret(Context ctx) {
        return !exp.interpret(ctx);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj != null && obj instanceof Not) {
            return this.exp.equals(((Not) obj).exp);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return this.toString().hashCode();
    }

    @Override
    public String toString() {
        return "(Not " + exp.toString() + ")";
    }
}